{% block sw_entity_single_select %}
<sw-select-base
    ref="selectBase"
    class="sw-entity-single-select"
    :is-loading="isLoading"
    :size="size"
    :disable-auto-close="disableAutoClose"
    v-bind="$attrs"
    :label="label"
    :disabled="disabled"
    @clear="clearInput"
    @select-expanded="onSelectExpanded"
    @select-collapsed="onSelectCollapsed"
>
    {% block sw_entity_single_select_base %}
    {% block sw_entity_single_select_base_selection %}
    <template #sw-select-selection="{ identification, error, disabled, size, setFocusClass, removeFocusClass }">
        {% block sw_entity_single_select_advanced_selection_modal %}
        <component
            :is="advancedSelectionComponent"
            v-if="isAdvancedSelectionActive && isAdvancedSelectionModalVisible"
            :is-single-select="true"
            :initial-search-term="advancedSelectionInitialSearchTerm"
            v-bind="advancedSelectionParameters"
            @modal-close="closeAdvancedSelectionModal"
            @selection-submit="onAdvancedSelectionSubmit"
        />
        {% endblock %}

        {% block sw_entity_single_select_base_selection_slot %}
        <div class="sw-entity-single-select__selection">
            {% block sw_entity_single_select_single_selection_inner %}
            {% block sw_entity_single_select_single_selection_inner_label %}
            <div
                v-if="!isExpanded"
                class="sw-entity-single-select__selection-text"
                :class="selectionTextClasses"
            >
                <template v-if="singleSelection">
                    <slot
                        name="selection-label-property"
                        v-bind="{ item: singleSelection, labelProperty, searchTerm, getKey }"
                    >
                        <sw-product-variant-info
                            v-if="displayVariants"
                            :variations="singleSelection.variation"
                        >
                            {{ displayLabelProperty(singleSelection) }}
                        </sw-product-variant-info>
                        <template v-else>
                            {{ displayLabelProperty(singleSelection) }}
                        </template>
                    </slot>
                </template>
                <template v-else>
                    {{ placeholder }}
                </template>
            </div>
            {% endblock %}
            {% block sw_entity_single_select_single_selection_inner_input %}
            <!-- eslint-disable-next-line vuejs-accessibility/form-control-has-label -->
            <input
                ref="swSelectInput"
                v-model="searchTerm"
                class="sw-entity-single-select__selection-input"
                :class="inputClasses"
                type="text"
                :placeholder="placeholder"
                :aria-label="label"
                @input="onInputSearchTerm"
            >
            {% endblock %}
            {% endblock %}
        </div>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_entity_single_select_base_results %}
    <template #results-list>
        {% block sw_entity_single_select_base_results_slot %}
        <sw-select-result-list
            ref="resultsList"
            :options="results"
            :is-loading="isLoading"
            :empty-message="$tc('global.sw-single-select.messageNoResults', { term: searchTerm })"
            :focus-el="$refs.swSelectInput"
            @paginate="paginate"
            @item-select="setValue"
        >
            {% block sw_entity_single_select_base_results_list %}
            {% block sw_entity_single_select_base_results_list_before %}
            <template #before-item-list>
                {% block sw_entity_single_select_base_results_list_before_advanced_selection %}
                <!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
                <div
                    v-if="isAdvancedSelectionActive"
                    class="sw-single-select-filtering__advanced-selection sw-select-result"
                    @click="openAdvancedSelectionModal"
                >
                    {{ $tc('global.sw-entity-advanced-selection-modal.link') }}
                </div>
                {% endblock %}

                {% block sw_entity_single_select_base_results_list_before_slot %}
                <slot name="before-item-list"></slot>
                {% endblock %}
            </template>
            {% endblock %}

            {% block sw_entity_single_select_base_results_list_result %}
            <template #result-item="{ item, index }">
                <slot
                    name="result-item"
                    v-bind="{ item, index, labelProperty, searchTerm, highlightSearchTerm, isSelected, setValue, getKey }"
                >
                    <sw-select-result
                        v-tooltip="getDisabledSelectionTooltip(item)"
                        :selected="isSelected(item)"
                        :disabled="isSelectionDisabled(item)"
                        :description-position="descriptionPosition"
                        v-bind="{ item, index }"
                        @item-select="setValue"
                    >
                        {% block sw_entity_multi_select_base_results_list_result_preview %}
                        <template
                            v-if="shouldShowActiveState"
                            #preview
                        >
                            {% block sw_entity_multi_select_base_results_list_result_active %}
                            <mt-icon
                                class="sw-entity-single-select__selection-active"
                                size="6"
                                :color="getActiveIconColor(item)"
                                name="solid-circle"
                            />
                            {% endblock %}
                        </template>
                        {% endblock %}

                        {% block sw_entity_single_select_base_results_list_result_label %}
                        <slot
                            name="result-label-property"
                            v-bind="{ item, index, labelProperty, searchTerm, highlightSearchTerm, getKey }"
                        >
                            <sw-product-variant-info
                                v-if="displayVariants"
                                :variations="item.variation"
                                :highlighted="true"
                                :search-term="searchTerm"
                            >
                                {{ displayLabelProperty(item) }}
                            </sw-product-variant-info>
                            <template v-else>
                                <sw-highlight-text
                                    v-if="highlightSearchTerm && !isSelected(item)"
                                    :text="displayLabelProperty(item)"
                                    :search-term="searchTerm"
                                />
                                <template v-else>
                                    {{ displayLabelProperty(item) }}
                                </template>
                            </template>
                        </slot>
                        {% endblock %}
                        {% block sw_entity_multi_select_base_results_list_result_description %}
                        <template #description>
                            <slot
                                name="result-description-property"
                                v-bind="{ item, searchTerm, highlightSearchTerm }"
                            ></slot>
                        </template>
                        {% endblock %}
                    </sw-select-result>
                </slot>
            </template>
            {% endblock %}

            {% block sw_entity_single_select_base_results_list_after %}
            <template #after-item-list>
                <slot name="after-item-list"></slot>
            </template>
            {% endblock %}
            {% endblock %}
        </sw-select-result-list>
        {% endblock %}
    </template>
    {% endblock %}
    {% endblock %}

    <template #label>
        <slot name="label"></slot>
    </template>

    <template #hint>
        <slot name="hint"></slot>
    </template>
</sw-select-base>
{% endblock %}
